import requests
from bs4 import BeautifulSoup
import pymysql
import re

start_url = 'http://books.toscrape.com'
next_page_url = start_url
while next_page_url:
    r = requests.get(next_page_url)
    r.raise_for_status()
    bs = BeautifulSoup(r.text,'html.parser')
    # ########爬取封面
    reg =r'src="(.+?\.jpg)"'
    imgre = re.compile(reg)
    imglist = re.findall(imgre,r.text)
    for i in imglist:
         print(i)


    # ########爬取作者
    author = bs.find_all('h3')
    for au in author:
        name =au.a['title']
        print(name)

    p = bs.find_all('p',class_ = "price_color")
    for _ in p:
        print(_.text)
# #######################################################
    # next_page = bs.find('li', class_='next')
    # if not next_page:
    #         # 如果没有下⼀⻚，结束爬⾍
    #     break
    #     # 取下⼀⻚的链接
    # next_page_url = next_page.a['href']
    #     # 拼装成完整的URL
    # next_page_url = start_url + next_page_url

# stock = bs.find_all('p',class_ = "instock availability")
# for j in stock:
#     print(j.text)

# print(bs)